import {getRequest, postRequest} from "@/utils/request.js";

/**
 * 账号密码登录请求
 * @param username
 * @param pwd
 * @returns {Promise<unknown>}
 */
export async function loginWithPwd(username, pwd) {
    try {
        return await getRequest('/heaven-server/login/loginWithPwd', {username, pwd});
    }catch (e) {
        console.log('登录失败',e);
        return {code: -1, msg: `登录失败-${e.message}`}
    }
}

/**
 * 获取登录状态
 * @returns {boolean}
 */
export async function getLoginStatus() {
    try {
        return await getRequest('/heaven-server/login/isLogin');
    }catch (e) {
        console.log('获取登录状态失败',e);
        return {code: -1, msg: `获取登录状态失败-${e.message}`}
    }
}

/**
 * 获取登录信息
 * @returns {Promise<unknown>}
 */
export async function getSession() {
    try {
        return await getRequest('/heaven-server/login/getSession');
    }catch (e) {
        console.log('获取登录信息失败',e);
        return {code: -1, msg: `获取登录信息失败-${e.message}`}
    }
}

export async function logout() {
    try {
        return await getRequest('/heaven-server/login/logout');
    } catch (e) {
        console.log('退出失败',e);
        return {code: -1, msg: `退出失败-${e.message}`}
    }
}

export function NotLoginCode() {
    return 20002;
}